﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WordService.Utility;

namespace WordLib
{
    public partial class MatrixSubForm : Form
    {
        public MatrixSubForm(String name, DataTable dt)
        {
            InitializeComponent();
            this._ExcelTable = dt;
            this.dgvMatrixResult.DataSource = dt;
            this.dgvMatrixResult.Update();
            this.lblTitle.Text = name;
        }

        private DataTable _ExcelTable = null;

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            if (this._ExcelTable != null && this._ExcelTable.Rows.Count > 0)
            {
                DialogResult result = this.fbdExportPath.ShowDialog();
                if (result == DialogResult.OK)
                {
                    String path = this.fbdExportPath.SelectedPath;
                    Microsoft.Office.Interop.Excel.Application
                        xAPP = ExcelUtil.ExportExcel(this._ExcelTable, this.lblTitle.Text.Replace(".","_"), ref path);
                    MessageBox.Show(this, "您的Excel已经导出成功！其路径为：" + path, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    // 导出为Excel的表格
                }
            }
            else
            {
                MessageBox.Show(this, "对不起，你选择的内容生成的矩阵为空，请重新设置相关信息！", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
    }
}
